package com.atstudy.headline.web.admin.controller.advertisement.adPerformanceDaily;

import com.atstudy.headline.entity.AdPerformanceDaily;
import com.atstudy.headline.result.Result;
import com.atstudy.headline.web.admin.service.AdPerformanceDailyService;
import com.atstudy.headline.web.admin.vo.ad.AdPerDailyVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/adPerDaily")
public class AdPerDailyController {
    @Autowired
    private AdPerformanceDailyService dailyService;

    @RequestMapping("/page")
    public Result<IPage<AdPerformanceDaily>> pageDictInfo(
            @RequestParam Integer current,
            @RequestParam Integer size,
            AdPerDailyVo queryVo) {
        Page<AdPerformanceDaily> page = new Page<>(current, size);

        QueryWrapper<AdPerformanceDaily> wrapper = new QueryWrapper<>();
        if(queryVo!=null){
            wrapper.eq("campaign_id",queryVo.getCampaignId());
            wrapper.between("stat_date",queryVo.getStartTime(),queryVo.getEndTime());
        }
        IPage<AdPerformanceDaily> creativesIPage = dailyService.pageInfoByAdPerDaily(page, queryVo);
        return Result.ok(creativesIPage);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Integer id){
        dailyService.removeById(id);
        return Result.ok();
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/deleteSelect")
    public Result deleteSelect(@RequestBody List<Integer> ids) {
        dailyService.removeByIds(ids);
        return Result.ok();
    }
}
